package org.lt.cj.view;

import java.awt.Rectangle;
import org.lt.cj.view.swing.BrandListDialog;
import org.lt.cj.view.swing.CollectionDialog;
import org.lt.cj.view.swing.TranslateDialog;

/**
 * @author zgh
 */
public class MainFrame extends javax.swing.JFrame {

    /** Creates new form MainFrame */
    public MainFrame() {
        initComponents();
        setLocationRelativeTo(null); //居中显示
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jCancelButton = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jCloseMenu = new javax.swing.JMenu();
        jCloseMenuItem = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jCollectionMenuItem = new javax.swing.JMenuItem();
        jTranslateMenuItem = new javax.swing.JMenuItem();
        jSendMenuItem = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenuItem7 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jCancelButton.setText("退出");
        jCancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCancelButtonActionPerformed(evt);
            }
        });

        jCloseMenu.setText("文件");
        jCloseMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCloseMenuActionPerformed(evt);
            }
        });

        jCloseMenuItem.setText("退出");
        jCloseMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCloseMenuItemActionPerformed(evt);
            }
        });
        jCloseMenu.add(jCloseMenuItem);

        jMenuBar1.add(jCloseMenu);

        jMenu2.setText("操作");

        jCollectionMenuItem.setText("采集");
        jCollectionMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCollectionMenuItemActionPerformed(evt);
            }
        });
        jMenu2.add(jCollectionMenuItem);

        jTranslateMenuItem.setText("翻译");
        jTranslateMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTranslateMenuItemActionPerformed(evt);
            }
        });
        jMenu2.add(jTranslateMenuItem);

        jSendMenuItem.setText("发送");
        jSendMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jSendMenuItemActionPerformed(evt);
            }
        });
        jMenu2.add(jSendMenuItem);

        jMenuBar1.add(jMenu2);

        jMenu3.setText("编辑");

        jMenuItem1.setText("编辑网址");
        jMenu3.add(jMenuItem1);

        jMenuItem2.setText("编辑分类");
        jMenu3.add(jMenuItem2);

        jMenuItem3.setText("编辑商家");
        jMenu3.add(jMenuItem3);

        jMenuItem4.setText("编辑产品");
        jMenu3.add(jMenuItem4);

        jMenuItem5.setText("编辑属性");
        jMenu3.add(jMenuItem5);

        jMenuItem6.setText("编辑评价");
        jMenu3.add(jMenuItem6);

        jMenuItem7.setText("编辑详情");
        jMenu3.add(jMenuItem7);

        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(391, Short.MAX_VALUE)
                .addComponent(jCancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(107, 107, 107))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(407, Short.MAX_VALUE)
                .addComponent(jCancelButton)
                .addGap(27, 27, 27))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jCollectionMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCollectionMenuItemActionPerformed
        // 采集对话框
        CollectionDialog cd = new CollectionDialog(this, true);
        Rectangle rect = new Rectangle();
        rect.setRect(this.getBounds());
        double x = rect.getX();
        double y = rect.getY();
        double width = rect.getWidth();
        double height = rect.getHeight();
        int w = cd.getWidth();
        int h = cd.getHeight();
        rect.setRect(x + (width - w) / 2, y + (height - h) / 2, w, h); //设置为父组件上面居中
        cd.setBounds(rect);
        cd.setVisible(true);
    }//GEN-LAST:event_jCollectionMenuItemActionPerformed

    private void jTranslateMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTranslateMenuItemActionPerformed
        // 翻译对话框

        Rectangle rect = new Rectangle();
        rect.setRect(this.getBounds());
        double x = rect.getX();
        double y = rect.getY();
        double width = rect.getWidth();
        double height = rect.getHeight();
        int w = td.getWidth();
        int h = td.getHeight();
        rect.setRect(x + (width - w) / 2, y + (height - h) / 2, w, h); //设置为父组件上面居中
        td.setBounds(rect);
        td.setVisible(true);
    }//GEN-LAST:event_jTranslateMenuItemActionPerformed

    private void jSendMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jSendMenuItemActionPerformed
        // 发送对话框
        BrandListDialog ptd = new BrandListDialog(this, true);
        Rectangle rect = new Rectangle();
        rect.setRect(this.getBounds());
        double x = rect.getX();
        double y = rect.getY();
        double width = rect.getWidth();
        double height = rect.getHeight();
        int w = ptd.getWidth();
        int h = ptd.getHeight();
        rect.setRect(x + (width - w) / 2, y + (height - h) / 2, w, h); //设置为父组件上面居中
        ptd.setBounds(rect);
        ptd.setVisible(true);
    }//GEN-LAST:event_jSendMenuItemActionPerformed

    private void jCancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCancelButtonActionPerformed
        this.dispose();
    }//GEN-LAST:event_jCancelButtonActionPerformed

    private void jCloseMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCloseMenuItemActionPerformed
        this.dispose();
    }//GEN-LAST:event_jCloseMenuItemActionPerformed

    private void jCloseMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCloseMenuActionPerformed
        this.dispose();
    }//GEN-LAST:event_jCloseMenuActionPerformed

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jCancelButton;
    private javax.swing.JMenu jCloseMenu;
    private javax.swing.JMenuItem jCloseMenuItem;
    private javax.swing.JMenuItem jCollectionMenuItem;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jSendMenuItem;
    private javax.swing.JMenuItem jTranslateMenuItem;
    // End of variables declaration//GEN-END:variables
    TranslateDialog td = new TranslateDialog(this, true);//可以确保只开启一个任务
}
